package com.bobi.tfca.network.api

import com.bobi.tfca.network.response.BaseResponse
import com.bobi.tfca.network.response.ChatRoomResponse
import com.bobi.tfca.network.response.MemberResponse
import com.bobi.tfca.network.response.MessageResponse
import okhttp3.MultipartBody
import okhttp3.RequestBody
import retrofit2.Call
import retrofit2.http.Body
import retrofit2.http.Field
import retrofit2.http.FormUrlEncoded
import retrofit2.http.GET
import retrofit2.http.Headers
import retrofit2.http.Multipart
import retrofit2.http.POST
import retrofit2.http.Part
import retrofit2.http.Path

interface MessageAPI {

    /**
     * 查询所有聊天室
     */
    @Headers("Accept: application/json")
    @GET("/chatRoom/findAll")
    fun getAllChatRooms(): Call<BaseResponse<ArrayList<ChatRoomResponse>>>

    /**
     * 查询历史消息
     */
    @Headers("Accept: application/json")
    @GET("/message/findCRMessages/{groupId}")
    fun getChatRoomMessages(@Path("groupId") groupId: Int): Call<BaseResponse<List<MessageResponse>>>

    /**
     * 修改群名
     */
    @Headers("Content-Type: text/plain", "Accept: application/json")
    @POST("/chatRoom/editGroupName/{groupId}")
    fun editGroupName(
        @Path("groupId") groupId: Int,
        @Body requestBody: RequestBody
    ): Call<BaseResponse<String>>

    /**
     * 解散群聊
     */
    @Headers("Accept: application/json")
    @GET("/chatRoom/disbandGroup/{groupId}")
    fun disbandGroup(@Path("groupId") groupId: Int): Call<BaseResponse<String>>

    /**
     * 添加群成员
     */
    @Headers("Content-Type: application/json;charset=utf-8", "Accept: application/json")
    @POST("/chatRoom/addMember2Group/{groupId}")
    fun addMember2Group(
        @Path("groupId") groupId: Int,
        @Body choseMemberIdList: List<Int>
    ): Call<BaseResponse<String>>

    /**
     * 删除群成员
     */
    @Headers("Accept: application/json")
    @POST("/chatRoom/removeMembers")
    @FormUrlEncoded
    fun removeMembers(@Field("memberIds") memberId: List<Int>, @Field("groupId") groupId: Int): Call<BaseResponse<String>>

    /**
     * 查询全部群成员
     */
    @Headers("Accept: application/json")
    @GET("/chatRoom/findAllGroupMembers/{groupId}")
    fun findAllGroupMembers(@Path("groupId") groupId: Int): Call<BaseResponse<List<MemberResponse>>>

    /**
     * 查询全部信件
     */
    @Headers("Accept: application/json")
    @GET("/letter/findAllLetters")
    fun findAllLetters(): Call<BaseResponse<List<MessageResponse>>>

    /**
     * 查询全部通知
     */
    @Headers("Accept: application/json")
    @GET("/notification/findAllNotifications")
    fun findAllNotifications(): Call<BaseResponse<List<MessageResponse>>>

    /**
     * 查询信件详情
     */
    @Headers("Accept: application/json")
    @GET("/letter/getLetterById/{letterId}")
    fun getLetterById(@Path("letterId") letterId: Long): Call<BaseResponse<MessageResponse>>

    /**
     * 写信
     */
    @Headers("Content-Type: text/plain", "Accept: application/json")
    @POST("/letter/writeLetter/{receiverId}")
    fun writeLetter(@Path("receiverId") receiverId: Int, @Body requestBody: RequestBody) : Call<BaseResponse<String>>

    /**
     * 查询通知详情
     */
    @Headers("Accept: application/json")
    @GET("/notification/getNotificationById/{notificationId}")
    fun getNotificationById(@Path("notificationId") notificationId: Long):  Call<BaseResponse<MessageResponse>>

    /**
     * 发布通知
     */
    @Headers("Content-Type: text/plain", "Accept: application/json")
    @POST("/notification/publishNotification")
    fun publishNotification(@Body requestBody: RequestBody) : Call<BaseResponse<String>>

    /**
     * 创建群聊
     */
    @Headers("Accept: application/json")
    @FormUrlEncoded
    @POST("/chatRoom/createGroup")
    fun createGroup(@Field("groupName") groupName: String, @Field("choseMemberIdList") choseMemberIdList: List<Int>):  Call<BaseResponse<String>>

    /**
     * 更新消息状态为已读
     */
    @Headers("Accept: application/json")
    @POST("/message/updateGroupMessageRead/{messageId}")
    fun updateGroupMessageRead(@Path("messageId") messageId: Long): Call<BaseResponse<String>>

    /**
     * 查询未读通知数量
     */
    @Headers("Accept: application/json")
    @GET("/notification/getUnReadNotificationNum")
    fun getUnReadNotificationNum(): Call<BaseResponse<Int>>

    /**
     * 查询未读信件数量
     */
    @Headers("Accept: application/json")
    @GET("/letter/getUnReadLetterNum")
    fun getUnReadLetterNum(): Call<BaseResponse<Int>>

    /**
     * 查询详情页面会员头像和昵称的列表
     */
    @Headers("Accept: application/json")
    @GET("/chatRoom/getGroupMemberHeadList/{groupId}")
    fun getGroupMemberHeadList(@Path("groupId") groupId: Int): Call<BaseResponse<ArrayList<MemberResponse>>>

    /**
     * 修改群头像
     */
    @Multipart
    @POST("/chatRoom/changeGroupHead/{groupId}")
    fun changeGroupHead(@Path("groupId") groupId: Int, @Part file: MultipartBody.Part): Call<BaseResponse<String>>


    /**
     * 检查是否有未读消息，用于定时发送通知提醒用户
     */
    @Headers("Accept: application/json")
    @GET("/message/checkNewMessage")
    fun checkNewMessage(): Call<BaseResponse<String>>
}